int height(struct TreeNode* root)
{
    if (root == NULL)
        return 0;
    int LeftHeight = height(root->left);
    int RightHeight = height(root->right);
    if (LeftHeight == -1 || RightHeight == -1 || fabs(LeftHeight - RightHeight) > 1)
    {
        return -1;
    }
    else
    {
        return fmax(LeftHeight, RightHeight) + 1;
    }
}

bool isBalanced(struct TreeNode* root) {
    return height(root) >= 0;
}